<?php
class DefaultDoLoginAction extends PiscesAction
{
	public function __construct()
	{
		parent::__construct();
		$this->responseType = 'json';
	}
	
	public function execute()
	{
		$this->code 	= 0;
		$password 		= trim($this->context->post('password'));
		$username 		= trim($this->context->post('username'));
		
		if($username!='' && $password!='')
		{
			$adminService	= new AdminService();
			$user	= $adminService->checkUserLogin($username,$password);
			if($user)
			{
				$adminService->updateLoginInfo($user['id'],$this->getIp(),Util::now());
				
				$this->code	= $user['id'];
				$authCode 	= $user['id'] . "\t" . $user['password'] ."\t" . $this->getIp();
				
				C("LtCookie")->setCookie('admin_auth', $authCode, time() + 86400);
				$this->data['forward'] = C('LtUrl')->generate('Default', 'Index');
			}
		}
	}
}